package com.innerex.inexclear.core.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * This class is used to represent available rule in the database.
 * 
 * @author <a href="mailto:evencia@innerex.com"> Edoardo Vencia
 *         (evencia@innerex.com)</a>
 */
@Entity
@Table(name = "clearingrule")
public class ClearingRule extends BaseObject implements Serializable {

	private static final long serialVersionUID = -4202223761971512783L;

	private Long id;
	private String description;
	private String javaClass;
	private String txClearing;

	/**
	 * Default constructor - creates a new instance with no values set.
	 */
	public ClearingRule() {
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	@Column(length = 64)
	public String getDescription() {
		return description;
	}

	@Column(length = 64)
	public String getJavaClass() {
		return javaClass;
	}

	@Column(length = 64)
	public String getTxClearing() {
		return txClearing;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setJavaClass(String javaClass) {
		this.javaClass = javaClass;
	}

	public void setTxClearing(String txClearing) {
		this.txClearing = txClearing;
	}

	/**
	 * {@inheritDoc}
	 */
	public int compareTo(Object o) {
		return (equals(o) ? 0 : -1);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String toString() {
		ToStringBuilder sb = new ToStringBuilder(this,
				ToStringStyle.DEFAULT_STYLE).append("id", this.getId()).append(
				"description", this.description).append("javaClass",
				this.javaClass).append("txClearing", this.txClearing);
		return sb.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
		result = prime * result
				+ ((javaClass == null) ? 0 : javaClass.hashCode());
		result = prime * result
				+ ((txClearing == null) ? 0 : txClearing.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (getClass() != obj.getClass())
			return false;
		ClearingRule other = (ClearingRule) obj;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (getId() == null) {
			if (other.getId() != null)
				return false;
		} else if (!getId().equals(other.getId()))
			return false;
		if (javaClass == null) {
			if (other.javaClass != null)
				return false;
		} else if (!javaClass.equals(other.javaClass))
			return false;
		if (txClearing == null) {
			if (other.txClearing != null)
				return false;
		} else if (!txClearing.equals(other.txClearing))
			return false;
		return true;
	}

}
